<template>
  <div v-loading="loading">
    <el-form ref="form" :model="form" :rules="rules" label-width="120px" class="dataForm" style="margin-left: 30px;">
      <div class="area-header">
        <span class="area-header-title">{{ $t('债券投资信息') }}</span>
      </div>
      <el-row>
        <el-col :span="12">
          <el-form-item :label="$t('债券投资成本(元)')" prop="investCost">
            <Money v-model="form.investCost" :placeholder="$t('债券投资成本(元)')" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('债券投资面值(元)')" prop="investFaceValue">
            <Money v-model="form.investFaceValue" :placeholder="$t('债券投资面值(元)')" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('债券投资规模(元)')" prop="investScale">
            <Money v-model="form.investScale" :placeholder="$t('债券投资规模(元)')" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('其中：信用债规模(元)')" prop="creditDebtScale">
            <Money v-model="form.creditDebtScale" :placeholder="$t('信用债规模(元)')" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('其中：AAA及以上信用债规模(元)')" prop="aaa">
            <Money v-model="form.aaa" :placeholder="$t('其中：AAA及以上信用债规模(元)')" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('AA+信用债规模(元)')" prop="aaAdd">
            <Money v-model="form.aaAdd" :placeholder="$t('AA+信用债规模(元)')" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item :label="$t('AA信用债规模(元)')" prop="aa">
            <Money v-model="form.aa" :placeholder="$t('AA信用债规模(元)')" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item :label="$t('AA-及以下信用债规模(元)')" prop="aaSub">
            <Money v-model="form.aaSub" :placeholder="$t('AA-及以下信用债规模(元)')" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item :label="$t('无评级信用债规模(元)')" prop="noneCredit">
            <Money v-model="form.noneCredit" :placeholder="$t('无评级信用债规模(元)')" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item :label="$t('债券正回购总额(元)')" prop="bondTotalRepurchase">
            <Money v-model="form.bondTotalRepurchase" :placeholder="$t('债券正回购总额(元)')" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item :label="$t('其中：质押式正回购金额(元)')" prop="pledgeTotalRepurchase">
            <Money v-model="form.pledgeTotalRepurchase" :placeholder="$t('质押式正回购金额(元)')" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item :label="$t('买断式正回购金额(元)')" prop="buyoutTotalRepurchase">
            <Money v-model="form.buyoutTotalRepurchase" :placeholder="$t('买断式正回购金额(元)')" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item :label="$t('债券逆回购总额(元)')" prop="totalBondReverseRepo">
            <Money v-model="form.totalBondReverseRepo" :placeholder="$t('债券逆回购总额(元)')" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item :label="$t('产品正回购杠杆比率(%)')" prop="productRepoRatio">
            <Money v-model="form.productRepoRatio" :placeholder="$t('产品正回购杠杆比率(%)')" />
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <div class="area-header">
          <span class="area-header-title">{{ $t('违约及风险债券信息') }}</span>
        </div>
        <el-col :span="12">
          <el-form-item :label="$t('持有违约债券只数')" prop="defaultBondNumber">
            <el-input-number v-model="form.defaultBondNumber" :placeholder="$t('持有违约债券只数')" :max="99999" :controls="false" :precision="0" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('持有风险债券只数')" prop="riskBondNumber">
            <el-input-number v-model="form.riskBondNumber" :placeholder="$t('持有风险债券只数')" :max="99999" :controls="false" :precision="0" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item :label="$t('违约或风险债券对产品产生的影响')" prop="productInfluence">
            <el-input v-model="form.productInfluence" type="textarea" :placeholder="$t('违约或风险债券对产品产生的影响')" show-word-limit maxlength="1000" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item :label="$t('违约或风险债券处置进展情况')" prop="progress">
            <el-input v-model="form.progress" type="textarea" :placeholder="$t('违约或风险债券处置进展情况')" show-word-limit maxlength="1000" />
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <div v-if="!btnHide && processBtn" slot="footer" class="dialog-footer" style="text-align: right;">
      <!--保存 取消按钮-->
      <save-btn has-permi="fund:monitor" />
    </div>
  </div>
</template>

<script>
    import { saveFundBondInvest, getByMonitorId } from '@/api/fund/operation/fundBondInvest'
    export default {
        data() {
            return {
                // 表单参数
                form: {},
                // 遮罩层
                loading: false,
                // 表单校验
                rules: {
                },
                processBtn: false,
                btnHide: false
            }
        },
        created() {
        },
        methods: {
            // 初始化数据
            init(data) {
                this.processBtn = data.processBtn
                this.btnHide = data.btnHide
                this.loading = true
                if (data.id !== undefined) {
                    getByMonitorId(data.id).then(response => {
                      if (response.data) {
                        this.form = response.data
                      } else {
                        this.reset()
                        this.form.monitorId = data.id
                      }
                        this.loading = false
                    })
                } else {
                    this.reset()
                    this.loading = false
                }
            },
            // 表单重置
            reset() {
                this.form = {
                    id: undefined,

                    monitorId: undefined,

                    investCost: undefined,

                    investFaceValue: undefined,

                    creditDebtScale: undefined,

                    aaa: undefined,

                    aaAdd: undefined,

                    aa: undefined,

                    aaSub: undefined,

                    noneCredit: undefined,

                    bondTotalRepurchase: undefined,

                    pledgeTotalRepurchase: undefined,

                    buyoutTotalRepurchase: undefined,

                    totalBondReverseRepo: undefined,

                    productRepoRatio: undefined,

                    defaultBondNumber: undefined,

                    riskBondNumber: undefined,

                    productInfluence: undefined,

                    progress: undefined,

                    createBy: undefined,

                    createTime: undefined,

                    updateBy: undefined,

                    updateTime: undefined

                }
                this.resetForm('form')
            },
            // 取消按钮
            cancel() {
                this.$emit('cancel')
                this.$parent.$parent.reset()
            },
            // 关闭form页面
            closeForm() {
                // 关闭form页面遮罩层
                this.loading = false
                // 关闭form页面
                if (this.$parent.$parent.formOpen !== undefined) {
                  this.$parent.$parent.formOpen = false
                }
                // 刷新list页面
                if (this.$parent.$parent.getList !== undefined) {
                  this.$parent.$parent.getList()
                }
            },
            /** 提交按钮 */
            submitForm: function() {
                this.$refs['form'].validate(valid => {
                    if (valid) {
                        this.loading = true
                        saveFundBondInvest(this.form).then(response => {
                            if (response.code === 200) {
                                this.form.id = response.data.id
                                this.msgSuccess(this.$t('保存成功'))
                                this.closeForm()
                            } else {
                                this.msgError(response.msg)
                            }
                            this.loading = false
                        })
                    } else {
                       this.locationError(document)
                    }
                })
           }

        }

    }
</script>
